﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["Homnay"] = 0;
        Application["ThangNay"] = 0;
        Application["TatCa"] = 0;
        Application["visitors_online"] = 0;
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        Session["user_login_admin"] = "";
        Application.Lock();
        Application["visitors_online"] = Convert.ToInt32(Application["visitors_online"]) + 1;
        Application.UnLock();
        try
        {
            SoTaiChinh.Library.Entity.ThongKe clsE_ThongKe = new SoTaiChinh.Library.Entity.ThongKe();
            SoTaiChinh.Library.Business.ThongKe clsB_ThongKe = new SoTaiChinh.Library.Business.ThongKe();
            System.Data.DataTable dt = clsB_ThongKe.SelectTruyCap(clsE_ThongKe);
            if (dt.Rows.Count > 0)
            {
                Application["HomNay"] = long.Parse("0" + dt.Rows[0]["HomNay"]).ToString("#,###");
                //Application["HomQua"] = long.Parse("0" + dt.Rows[0]["HomQua"]).ToString("#,###");
                Application["TuanNay"] = long.Parse("0" + dt.Rows[0]["TuanNay"]).ToString("#,###");
                //Application["TuanTruoc"] = long.Parse("0" + dt.Rows[0]["TuanTruoc"]).ToString("#,###");
                Application["ThangNay"] = long.Parse("0" + dt.Rows[0]["ThangNay"]).ToString("#,###");
                //Application["ThangTruoc"] = long.Parse("0" + dt.Rows[0]["ThangTruoc"]).ToString("#,###");
                Application["TatCa"] = long.Parse("0" + dt.Rows[0]["TatCa"]).ToString("#,###");
            }
            dt.Dispose();            
        }
        catch { }
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application.Lock();
        Application["visitors_online"] = Convert.ToUInt32(Application["visitors_online"]) - 1;
        Application.UnLock();
    }
       
</script>
